//
//  RechargeApplicationViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/5/11.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define UISCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
#define UISCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#import "RechargeApplicationViewController.h"

@interface RechargeApplicationViewController ()<UITextFieldDelegate>
{
    UILabel *rechargeApplicationLabel2;
    UILabel *rechargeApplicationLabel3;
    UILabel *rechargeApplicationLabel4;
    
    int secondsCountDown; //倒计时总时长
    NSTimer *countDownTimer;
    UILabel *labelText;

}

@end

@implementation RechargeApplicationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"充值申请";
    self.view.backgroundColor = [UIColor redColor];
    
    self.rechargeApplicationtitles1 = @[@"收款E-mail:",@"收款户名:",@"收款账号:",@"开户银行:"];
    self.rechargeApplicationtitles2 = @[@"kwnaoigv@qq.com",@"江艳梅",@"6210564822265654587",@"上海市闵行南方商城支行"];
    
    rechargeApplicationtableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT) style:UITableViewStylePlain];
    rechargeApplicationtableView.dataSource = self;
    rechargeApplicationtableView.delegate = self;
    rechargeApplicationtableView.scrollEnabled = NO;
    rechargeApplicationtableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:rechargeApplicationtableView];
    
    rechargeApplicationtableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
    rechargeApplicationtableView.tableHeaderView.backgroundColor = [UIColor whiteColor];
    
//    UITextField *rechargeApplicationTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMinY(rechargeApplicationtableView.tableHeaderView.frame)+10, UISCREEN_WIDTH-10-10, 50)];
//    rechargeApplicationTextField.returnKeyType = UIReturnKeyDone;  //返回按钮的样式
//    rechargeApplicationTextField.clearButtonMode = YES; //清除模式开启
//    rechargeApplicationTextField.secureTextEntry = YES; //密码输入框
////    rechargeApplicationTextField.backgroundColor = [UIColor redColor];
//    rechargeApplicationTextField.placeholder = @"充值附言：";
//    //协议执行者交给textField自己self
//    rechargeApplicationTextField.delegate = self;
//    [rechargeApplicationtableView.tableHeaderView addSubview:rechargeApplicationTextField];

//    UILabel *rechargeApplicationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(rechargeApplicationTextField.frame)+5, UISCREEN_WIDTH-10-10, 20)];
//    rechargeApplicationLabel.text = @"订单金额：9855";
//    [rechargeApplicationtableView.tableHeaderView addSubview:rechargeApplicationLabel];
    
    [self rechargeApplicationLabels];
    
    [self labelText];

}

-(void)labelText{

    //创建UILabel
    labelText=[[UILabel alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH-100)/2, 80+20+20+15+45*4, 100, 50)];
    labelText.backgroundColor = [UIColor blackColor];
    labelText.textAlignment = NSTextAlignmentCenter;
    labelText.textColor = [UIColor whiteColor];
    labelText.font = [UIFont systemFontOfSize:25];
    //设置倒计时总时长
    secondsCountDown = 1800;//60秒倒计时
    //开始倒计时
    countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; //启动倒计时后会每秒钟调用一次方法 timeFireMethod
    
    //设置倒计时显示的时间
    //    labelText.text=[NSString stringWithFormat:@"%d",secondsCountDown];
    NSString *secondValue = [NSString stringWithFormat:@"%u:%02u",(secondsCountDown/60)%60,secondsCountDown%60];
    labelText.text= secondValue;

}
// 倒计时方法
-(void)timeFireMethod{
    //倒计时-1
    secondsCountDown--;
    //修改倒计时标签现实内容
    //    labelText.text=[NSString stringWithFormat:@"%d",secondsCountDown];
    NSString *secondValue = [NSString stringWithFormat:@"%u:%02u",(secondsCountDown/60)%60,secondsCountDown%60];
    labelText.text= secondValue;
    //当倒计时到0时，做需要的操作，比如验证码过期不能提交
    if(secondsCountDown==0){
        [countDownTimer invalidate];
        [labelText removeFromSuperview];
    }
}


-(void)rechargeApplicationLabels{
    rechargeApplicationLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 80*2+20*2+45*4+1, UISCREEN_WIDTH, 20)];
    rechargeApplicationLabel2.text = @"请在30分钟内完成汇款，逾期订单将失效";
    rechargeApplicationLabel2.textAlignment = NSTextAlignmentCenter;
    rechargeApplicationLabel2.textColor = [UIColor grayColor];
    rechargeApplicationLabel2.backgroundColor = [UIColor clearColor];
    rechargeApplicationLabel2.font = [UIFont systemFontOfSize:10];
    
    rechargeApplicationLabel3 = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(rechargeApplicationLabel2.frame)+1, UISCREEN_WIDTH, 20)];
    rechargeApplicationLabel3.text = @"您需重新发起充值申请";
    rechargeApplicationLabel3.textAlignment = NSTextAlignmentCenter;
    rechargeApplicationLabel3.textColor = [UIColor grayColor];
    rechargeApplicationLabel3.backgroundColor = [UIColor clearColor];
    rechargeApplicationLabel3.font = [UIFont systemFontOfSize:10];
    
    rechargeApplicationLabel4 = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(rechargeApplicationLabel3.frame)+1, UISCREEN_WIDTH, 20)];
    rechargeApplicationLabel4.text = @"请继续在网银客户端或银行柜台完成后续操作";
    rechargeApplicationLabel4.textAlignment = NSTextAlignmentCenter;
    rechargeApplicationLabel4.textColor = [UIColor grayColor];
    rechargeApplicationLabel4.backgroundColor = [UIColor clearColor];
    rechargeApplicationLabel4.font = [UIFont systemFontOfSize:10];

    
}

//UITextField控件协议方法：当点击返回按钮时方法执行
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 4;
    }else if (section == 1){
        return 1;
    }else{
        return 1;
    }
}

//设置表视图中的section（分组）数,默认为1
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
}

// 设置header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section < 2) {
        return 20;
    }else{
        return 80;
    }
}

- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 1) {
        return 80;
    }else{
        return 45;
    }
}



//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *myCell = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCell];
    
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCell];
        
        cell.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont systemFontOfSize:16];
        cell.textLabel.textColor = [UIColor blackColor];
        
        UILabel *bettingInformationLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, (45-30)/2, 200, 30)];
        bettingInformationLabel.tag = 105;
        bettingInformationLabel.textColor = [UIColor grayColor];
        bettingInformationLabel.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bettingInformationLabel];

        
    }
    UILabel *bettingInformationLabel = (UILabel *)[cell.contentView viewWithTag:105];

    //设置数据
    if (indexPath.section == 0) {
        cell.textLabel.text = _rechargeApplicationtitles1[indexPath.row];
        bettingInformationLabel.hidden = NO;
        bettingInformationLabel.text = _rechargeApplicationtitles2[indexPath.row];
    }else if(indexPath.section == 2){
        cell.textLabel.text = @"已经完成银行汇款";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.backgroundColor = [UIColor colorWithRed:46/255.0f green:168/255.0f blue:289/255.0f alpha:1];
    }
    [rechargeApplicationtableView addSubview:rechargeApplicationLabel2];
    [rechargeApplicationtableView addSubview:rechargeApplicationLabel3];
    [rechargeApplicationtableView addSubview:rechargeApplicationLabel4];
    [rechargeApplicationtableView addSubview:labelText];
    return cell;
    
}

@end
